package com.lcxw.hxzbapi.dao.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.lcxw.hxzbapi.entity.pojo.YwpdRoom;

@Mapper
public interface YwpdRoomMapper {

    @Insert("insert into ywpd_room ("
        + "roomId, roomName, userId, bakPicUrl, pullUrl, pushUrl,  "
        + "creatTime, `union`, unionId, liveStatus, roomNotice, "
        + "attentionNum, longitude, latitude, city  "
        + ") VALUES ("
        + "#{roomId}, #{roomName}, #{userId}, #{bakPicUrl}, #{pullUrl}, #{pushUrl}, "
        + "#{creatTime}, #{union}, #{unionId}, #{liveStatus}, #{roomNotice}, "
        + "#{attentionNum}, #{longitude}, #{latitude}, #{city} "
        + ")"
    )
    int insert(YwpdRoom ywpdRoom) throws Exception;

    @Select("SELECT * FROM ywpd_room WHERE roomId = #{roomId}")
    YwpdRoom selectRoomByRoomId(long roomId);

    @Select("SELECT * FROM ywpd_room WHERE userId = #{userId}")
    YwpdRoom selectRoomByUserId(long userId);

    @Select("SELECT COUNT(unionId) FROM ywpd_room WHERE unionId=#{unionId}")
    int selectRoomCountOfUnionId(long unionId) throws Exception;

    @Update({
        "update ywpd_room",
        "set roomId = #{roomId},",
        "roomName = #{roomName},",
        "userId = #{userId},",
        "roomType = #{roomType},",
        "bakPicUrl = #{bakPicUrl},",
        "pullUrl = #{pullUrl},",
        "pushUrl = #{pushUrl},",
        "creatTime = #{creatTime},",
        "`union` = #{union},",
        "unionId = #{unionId},",
        "liveStatus = #{liveStatus},",
        "roomNotice = #{roomNotice},",
        "attentionNum = #{attentionNum},",
        "longitude = #{longitude},",
        "latitude = #{latitude},",
        "city = #{city} ",
        "where roomId = #{roomId}"
    })
    int updateRoomByRoomId(YwpdRoom ywpdRoom);

    /**
     * 查询所有roomId
     */
    @Select("SELECT roomId from ywpd_room")
    List<Long> selectAllRoomId();

    /**
     * 用房间类型获取当前在播的房间
     */
    @Select("select * from ywpd_room where liveStatus=1 and roomType=#{roomType}")
    List<YwpdRoom> selectLivingRoomByRoomType(String roomType)throws Exception;

    /**
     * 获取当前在播的所有房间
     */
    @Select("select * from ywpd_room where liveStatus=1")
    List<YwpdRoom> selectAllLivingRoom()throws Exception;

    /**
     * 获取当前在播的所有房间
     */
    @Select("select roomId from ywpd_room where liveStatus=1")
    List<Long> selectAllLivingRoomId();
}
